{extend name="public:layout" /}
{block name="title"}商品管理{/block}
{block name="head"}
<style>
    i{cursor:pointer}
</style>
{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 商品列表</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <div class="pull-left">
                    <button class="btn btn-white" type="button"
                            onclick="updateOrder()">
                        <i class="fa fa-sort"></i>更新排序
                    </button>
                    <a class="btn btn-primary" href="{:url('add',['cid'=>$Request.param.cid])}">
                        <i class="fa fa-plus"></i>&nbsp;添加商品
                    </a>
                </div>
                <div class="pull-right">
                    <form class="form-inline" method="post" id="searchForm">
                        <input type="hidden" name="goodstype" id="goodstype" value="{$query.goodstype}" />
                        <div class="form-group">
                            <select class="form-control" name="property">
                                <option value="">所有</option>
                                <option value="is_best" {eq name="query.property" value="is_best"}selected{/eq}>精品</option>
                                <option value="is_new" {eq name="query.property" value="is_new"}selected{/eq}>新品</option>
                                <option value="is_hot" {eq name="query.property" value="is_hot"}selected{/eq}>热销</option>
                                <option value="is_commend" {eq name="query.property" value="is_commend"}selected{/eq}>推荐</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <input class="form-control" name="goods_name" value="{$query.goods_name}" type="text" placeholder="检索关键词">
                        </div>
                        <button type="submit" class="btn btn-info">
                            <i class="fa fa-search"></i> 搜索
                        </button>
                        <a class="btn btn-white" href="{:url('index')}">
                            <i class="fa fa-trash"></i> 清空
                        </a>
                    </form>
                </div>
                <div class="clearfix"></div>
            </div>
            <ul class="nav nav-tabs" id="tab_search">
                <li data-val="0" onclick="setGoodstype(this)" {eq name="query.goodstype" value="0"}class="active"{/eq}><a href="javascript:;">所有商品</a></li>
                <li data-val="1" onclick="setGoodstype(this)" {eq name="query.goodstype" value="1"}class="active"{/eq}><a href="javascript:;">上架</a></li>
                <li data-val="2" onclick="setGoodstype(this)" {eq name="query.goodstype" value="2"}class="active"{/eq}><a href="javascript:;">下架</a></li>
                <li data-val="3" onclick="setGoodstype(this)" {eq name="query.goodstype" value="3"}class="active"{/eq}><a href="javascript:;">预售</a></li>
                <li data-val="4" onclick="setGoodstype(this)" {eq name="query.goodstype" value="4"}class="active"{/eq}><a href="javascript:;">限时</a></li>
                <li data-val="5" onclick="setGoodstype(this)" {eq name="query.goodstype" value="5"}class="active"{/eq}><a href="javascript:;">积分</a></li>
                <li data-val="6" onclick="setGoodstype(this)" {eq name="query.goodstype" value="6"}class="active"{/eq}><a href="javascript:;">集采</a></li>
                <li data-val="7" onclick="setGoodstype(this)" {eq name="query.goodstype" value="7"}class="active"{/eq}><a href="javascript:;">竞拍</a></li>
            </ul>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="50">#</th>
                    <th>排序</th>
                    <th>商品名称</th>
                    <th width="120">类目</th>
                    <th width="50">精品</th>
                    <th width="50">新品</th>
                    <th width="50">热销</th>
                    <th width="50">推荐</th>
                    <th width="50">状态</th>
                    <th width="120">操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="list" id="vo"}
                <tr>
                    <td>{$vo.goods_id}</td>
                    <td width="80"> <input type="text" class="form-control list_order"
                                name="list_order[{$vo.goods_id}]" value="{$vo['goods_sort']}"/>
                    </td>
                    <td>
                        <img src="{$vo.goods_thumb|default='/public/nopic.gif'}" class="pull-left" style="width:32px;height:32px;margin:4px;" />
                                {$vo.goods_name}
                    </td>
                    <td>{$category[$vo['cid']]['cat_name']}</td>
                    <td>
                        {eq name="vo.is_best" value="1"}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_best','0');" class="fa fa-check text-success"> </i>
                        {else/}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_best','1');" class="fa fa-close text-warning"> </i>
                        {/eq}
                    </td>
                    <td>
                        {eq name="vo.is_new" value="1"}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_new','0');" class="fa fa-check text-success"> </i>
                        {else/}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_new','1');" class="fa fa-close text-warning"> </i>
                        {/eq}
                    </td>
                    <td>
                        {eq name="vo.is_hot" value="1"}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_hot','0');" class="fa fa-check text-success"> </i>
                        {else/}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_hot','1');" class="fa fa-close text-warning"> </i>
                        {/eq}
                    </td>
                    <td>
                        {eq name="vo.is_commend" value="1"}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_commend','0');" class="fa fa-check text-success"> </i>
                        {else/}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_commend','1');" class="fa fa-close text-warning"> </i>
                        {/eq}
                    </td>
                    <td>
                        {eq name="vo.is_on_sale" value="1"}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_on_sale','0');" class="fa fa-check text-success"> </i>
                        {else/}
                        <i onclick="setStatus(this,'{$vo.goods_id}','is_on_sale','1');" class="fa fa-close text-warning"> </i>
                        {/eq}
                    </td>
                    <td>
                        <a href="{:url('copy',['goods_id'=>$vo['goods_id']])}">拷贝</a>
                        <a href="{:url('edit',['goods_id'=>$vo['goods_id']])}">编辑</a>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认删除吗？" data-url="{:url('del')}" data-params="goods_id={$vo.goods_id}">删除</a>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
            <div class="page-bar">{$list->render()}</div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('#cid').change(function () {
            $('#searchForm').submit();
        });
    });
    //选取商品类型
    function setGoodstype(obj) {
        var goodstype = $(obj).data('val');
        $('#goodstype').val(goodstype);
        $('#searchForm').submit();
    }
    //更新排序
    function updateOrder() {
        if ($(".list_order").length > 0) {
            var data = $(".list_order").serialize();
            var url = "{:url('updateOrder')}";
            getAjax(url, data, function (data) {
                top.layer.msg(data.msg, {icon: 1, time: 800}, function () {
                    rePage();
                });
            });
        }
    }
    //切换状态
    function setStatus(obj,goodsId,field,status){
        var url="{:url('setStatus')}";
        var params = {goods_id:goodsId,field:field,status:status};
        getAjax(url, params, function (res) {
            rePage();
        });
    }
</script>
{/block}